package com.hos.operation.push.gtui;


import com.gexin.rp.sdk.base.notify.Notify;
import com.gexin.rp.sdk.dto.GtReq;
import com.hos.utile.DLog;
import com.hos.utile.JsonUtile;

import java.security.SecureRandom;

/**
 * 大医消息推送
 * Created by Administrator on 2018/8/24 0024.
 */
public class PushTest extends PushManager {
    private static PushTest pushManager;
    private String appId = "54NONCy9U68EBQwRQ2slo7";
    private String appKey = "ZFPlIi3iH29Sqm4I7BCLX5";
    private String masterSecret = "EgvRkH7DQfAKb8igQcMev1";

    //appId：	54NONCy9U68EBQwRQ2slo7
    //appKey：	ZFPlIi3iH29Sqm4I7BCLX5
    //appSecret：	Fzn0tE4qAp6SUiBrs731Z7
    //应用包名：	com.hztywl.hnyl.pat
    //masterSecret：	EgvRkH7DQfAKb8igQcMev1
    public static PushTest getInstance() {
        if (pushManager == null) {
            pushManager = new PushTest();
        }
        return pushManager;
    }

    @Override
    String getAppId() {
        return appId;
    }

    @Override
    String getAppKey() {
        return appKey;
    }

    @Override
    String getMasterSecret() {
        return masterSecret;
    }

    public void pushTest() {
        String a1 = "";
        String a2 = ";end";

        String pushId = "";
        PushBaseBean baseBean = null;
        //大医
        // baseBean = new DataDyBean();
        //浙二
        //baseBean = new DataZeBean();
        //吉安好医生
        //baseBean = new DataJABean();
        //东阳人民医院
        //baseBean = new DataDYRMYYBean();
        //一龄
        baseBean = new DataYLBean();
        DLog.e("推送一龄");
        //
        boolean isDoc = false;
        appId = baseBean.getAppId(isDoc);
        appKey = baseBean.getAppKey(isDoc);
        masterSecret = baseBean.getMasterSecret(isDoc);
        a1 = baseBean.getIntent(isDoc);
        if (isDoc) {
            //医生端
            pushId = "bbc65eee9b5fb13fa9bfa0109eecdd8f";
            DLog.e("推送给医生端");
        } else {
            //患者端
            pushId = "4d142e688b09cb4fa5410e7a78869af4";
            DLog.e("推送给患者端");
        }
        TestBean testBean = new TestBean();
        String msg = JsonUtile.obj2Json(testBean);
        Notify notify = new Notify();
        notify.setTitle(titile);
        notify.setContent(testBean.alertBody);
        //设置离线推送
        if (a1 != null && a1.length() > 0) {
            notify.setIntent(a1 + msg + a2);
            //小米 不用做其它设置
            //oppo 不用做其它设置
            //vivo
            setVivo(notify);
            //setHwBadge(notify);
        }
        notify.setType(GtReq.NotifyInfo.Type._intent);
        DLog.e("推送id=" + pushId + " 设置" + notify.toString());
        //APNPayload payload = setIOS(titile, testBean.alertBody);
        onPush(pushId, msg, notify, null);

    }

    //vivo推送设置
    private void setVivo(Notify notify) {
        //vivo 0：一天限制5条（运营消息） 1：推送不限制（系统消息）
        notify.addVVExtKV("classification", 1);
    }

    //设置华为角标
    //1:华为应用开启离线推送
    //2:华为应用设置 SHA256 指纹
    //3: app LaunchActivity设置 android:exported="true"
    //4：下载agconnect-services.json到app目录下
    private void setHwBadge(Notify notify) {
        notify.setChannelId("11");
        notify.setNotifyId(111);
        //华为角标设置
        //badgeAddNum：角标数字，取值范围1-99
        notify.addHWExtKV("badgeAddNum", 14);
        // badgeClass：桌面图标对应的应用入口Activity类
        notify.addHWExtKV("badgeClass", "com.app.ui.activity.launch.LaunchActivity");
    }


    private String index = getRandom();
    private String titile = "你好oppo" + index;

    class TestBean {
        public String alertBody = "推送内容" + index;
    }

    //获取随机码
    private String getRandom() {
        SecureRandom random = new SecureRandom();
        String randoms = "";
        for (int i = 0; i < 4; i++) {
            int randomInt = random.nextInt(9);
            randoms += randomInt;
        }
        return randoms;
    }
}
